package com.game.element
{
	import com.interfaces.game.GlobalAPI;
	import com.interfaces.general.mangaer.IDispose;
	import com.interfaces.general.mangaer.ITick;
	
	import flash.display.Shape;
	import flash.geom.Point;
	import flash.utils.getTimer;
	
	public class Bullet extends Shape implements ITick,IDispose
	{
		public var targetPoint:Point;
		public var speed:int;
		private var lastCheckTime:int;
		public var damage:Number;
		public var impactForce:Number;
		public var fireMan:BaseElement;
		
		public function Bullet()
		{
			super();
			this.graphics.beginFill(0xFF9900,1);
			this.graphics.drawRect(-5,-5,10,10);
			this.graphics.endFill();
		}
		
		public function exce():void
		{
			if(lastCheckTime == 0){
				lastCheckTime = getTimer();
				return;
			}
			var d:Number = getTimer()-lastCheckTime ;
			lastCheckTime = getTimer();
			
			var ds :Number = d/1000*speed;
			var p:Point = new Point(this.x,this.y);
			var p2:Point = targetPoint;
			var p3:Point = p2.subtract(p);
			if(p3.length <= ds ){
				dispose();
			}else{
				p3.normalize(ds);
				var dd:Point = p.add(p3);
				this.x = dd.x;
				this.y = dd.y;
			}
		}
		
		public function dispose():void{
			GlobalAPI.tickManager.unRegeditTick(this);
			if(this.parent != null && this.parent.contains(this)){
				this.parent.removeChild(this);
			}
		}
		
		public function set tickPriority(priority:int):void
		{
		}
		
		public function get tickPriority():int
		{
			return 0;
		}
	}
}